package grape.sequence.service.generator.periodparser;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import grape.common.tools.ThreadContextTool;
import grape.sequence.service.config.po.Config;

import java.util.Date;

/**
 * Created by yangwei
 * Created at 2020/8/22 13:09
 */
public class ParserHelper {

    public static Date getNow() {
        Date now = new Date();
        Object o = ThreadContextTool.get(IPeriodUnitParser.class.getName() + "now");
        if (o != null) {
            now = ((Date) o);
        }
        return now;
    }

    public static Date getStart(Config config) {
        Date start = DateUtil.date(config.getCreateAt());
        if (config.getIsPeriodFormFirstGenerateAt() != null && config.getIsPeriodFormFirstGenerateAt()) {
            if (config.getFirstGenerateAt() == null) {
                return new DateTime();
            }
            start = DateUtil.date(config.getFirstGenerateAt());
        }
        return start;
    }
}
